<?php if ( ! defined( 'BASEPATH' ) ) exit( 'No direct script access allowed' );

/**
 * BackendPro
 *
 * A website backend system for developers for PHP 4.3.2 or newer
 *
 * @package         conlabz CMS
 * @author          Christian Schneider
 * @copyright       Copyright (c) 2009
 * @license         
 * @link            http://www.conlabz.de
 * @filesource
 */

// ---------------------------------------------------------------------------

/**
 * Website_model
 *
 * Model used to retrive webites
 *
 * @package			conlabz CMS
 * @subpackage		Models
 */
class Classification_model extends Base_model {
	function Classification_model( ) {
		parent::Base_model( );

		$this->_TABLES = array( 'Option' => $this->config->item( 'backendpro_table_prefix' ) . 'article' );

		// Cache to store already fetched items
		$this->_CACHE = array( );

		// Object keyword
		// I wouldn't advise changing this, it could corrupt current
		// articles, the reason for needing this is to stop unserialze
		// errors spamming the log files
		$this->object_keyword = "BeP::Object::";

		log_message( 'debug', 'conlabz CMS : Classification_model class loaded' );
	}

	/**
	 * Get Classification
	 *
	 * @access public
	 * @param mixed $where Where query string/array
	 * @param array $limit Limit array including offset and limit values
	 * @return object
	 */
	function getClassifications( $where = NULL, $limit = array( 'limit' => NULL, 'offset' => '' ) ) {
		$this->db->select( 'classification.id, classification.name, classification.description' );
		$this->db->from( "classification" );
		if( !is_null( $where ) ) {
			$this->db->where( $where );
		}
		if( !is_null( $limit['limit'] ) ) {
			$this->db->limit( $limit['limit'], ( isset( $limit['offset'] ) ? $limit['offset'] : '' ) );
		}
		$this->db->order_by( 'classification.name desc' ); 
		return $this->db->get( );
	}
	
	/**
	 * Insert new Classification
	 *
	 * @access public
	 * @param array $data Data array
	 */
	function insert( $data = array( ) ) {
		//get user_ref from session object
		$data['user_ref'] = $this->session->userdata( 'id' );
		
		//create new website entry
		$this->db->set( 'id',          $data['id']          );
		$this->db->set( 'name',        $data['title']       );
		$this->db->set( 'description', $data['description'] );

		//insert the new classification
		$this->db->insert( 'classification' );
		
		return $this->db->insert_id( );
	}
	
	/**
	 * Constructs an array of the given classification to be used for a dropdown menu
	 *
	 * @access public
	 * @return array
	 */
	function buildClassificationDropdown( ) {
		$classifications = $this->getClassifications( );
		
		$dropdown = '';
		foreach( $classifications->result( ) as $row ) {
	    	 $dropdown[$row->id] = $row->name;
		}
		
		return $dropdown;
	}	
}
/* End of file classification_model.php */
/* Location: ./modules/articles/models/classification_model.php */